<template>
    <div>
        <table class="table" id="fix_table"></table>
        <div class="modal fade" id="fix_ok_bx_modal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>

                    </div>
                    <div class="modal-body">
                          确认修好？该操作不可返回！
                     </div>
                     <div class="modal-footer">
                         <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" @click="update">确认</button>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                currentRow: ''
            }
        },
        methods: {
            getFixTable() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/assetsfix/fetchlist',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid,
                        'extra.pagesize': 99999999,
                        'extra.pageindex': 1
                    },
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {

                        if (retdata.Table1[0].status == true) {
                            for (var i = 0; i < retdata.Table2.length; i++) {
                                retdata.Table2[i].fentdte = retdata.Table2[i].fentdte.substring(0, 10)
                                retdata.Table2[i].fixokdate = retdata.Table2[i].fixokdate.substring(0, 10)
                                retdata.Table2[i].fokdate = retdata.Table2[i].fokdate.substring(0, 10)
                                if (retdata.Table2[i].fixok == true) {
                                    retdata.Table2[i].fixok = '是'
                                }
                                if (retdata.Table2[i].fixok == false) {
                                    retdata.Table2[i].fixok = '否'
                                }
                                if (retdata.Table2[i].fisok == true) {
                                    retdata.Table2[i].fisok = '是'
                                }
                                if (retdata.Table2[i].fisok == false) {
                                    retdata.Table2[i].fisok = '否'
                                }
                            }
                        }
                        var operateEvents = {
                            'click a[name="handle"]': function(elem, value, row, index) {
                                _this.currentRow = row
                                _this.showTipModal()
                            }
                        }
                        $('#fix_table').bootstrapTable('destroy')
                        $('#fix_table').bootstrapTable({
                            columns: [{
                                radio: true
                            }, {
                                field: 'fidno',
                                title: '维保单号',
                                halign: 'center'
                            }, {
                                field: 'fassetsid',
                                title: '资产编号',
                                class: 'hidden'
                            }, {
                                field: 'fbarcode',
                                title: '物料型号',
                                halign: 'center',
                                class: 'hidden'
                            }, {
                                field: 'fname',
                                title: '维保物品名',
                                halign: 'center'
                            }, {
                                field: 'fdescription',
                                title: '故障描述',
                                halign: 'center'
                            }, {
                                field: 'fdname2',
                                title: '请修部门',
                                halign: 'center'
                            }, {
                                field: 'fdname',
                                title: '维保部门',
                                halign: 'center'
                            }, {
                                field: 'ftype',
                                title: '维保类型',
                                halign: "center"
                            }, {
                                field: 'fentdte',
                                title: '报修日期',
                                halign: 'center'
                            }, {
                                field: 'fixok',
                                title: '是否维保完毕',
                                halign: 'center'
                            }, {
                                field: 'fixokdate',
                                title: '维保完毕时间',
                                halign: 'center'
                            }, {
                                field: 'fisok',
                                title: '是否确认修好',
                                halign: 'center'
                            }, {
                                field: 'fokdate',
                                title: '确认修好时间',
                                halign: 'center'
                            }, {
                                field: 'operate',
                                title: '操作',
                                halign: 'center',
                                formatter: '<a class="btn btn-success btn-sm" name="handle">确认修好</a>',
                                events: operateEvents
                            }],
                            data: retdata.Table2,
                            pagination: true,
                            paginationLoop: true,
                            onlyInfoPagination: false,
                            striped: true,
                            sidePagination: 'client',
                            pageNumber: 1,
                            pageSize: 10,
                            pageList: [10, 25, 50, 100, 200, 500],
                            smartDisplay: true,
                            selectItemName: 'assets',
                            showHeader: true,
                            maintainSelected: true,
                            clickToSelect: true,
                            singleSelect: false,
                            checkboxHeader: true,
                        })
                    }
                });
            },
            showTipModal() {
                console.log(this.currentRow.assetsid)
                $('#fix_ok_bx_modal').modal('show')
            },
            update() {
                var mydate = this.getnowtime()
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/assetsfix/update',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid,
                        'fidno': _this.currentRow.fidno,
                        'fassetsid': _this.currentRow.fassetsid,
                        'ftype': _this.currentRow.ftype,
                        'fdescription': _this.currentRow.fdescription,
                        'fdeptid': _this.currentRow.fdeptid,
                        'fixok': true,
                        'fixokdate': mydate,
                        'fisok': false,
                        'fokdate': _this.currentRow.fixokdate,
                        'fixnotes': ''
                    },
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },

                    success: function(retdata) {
                        $('#fix_ok_bx_modal').modal('hide')
                        _this.getFixTable()
                    }
                });
            },
            getnowtime() {
                var nowtime = new Date();
                var year = nowtime.getFullYear();
                var month = this.padleft0(nowtime.getMonth() + 1);
                var day = this.padleft0(nowtime.getDate());
                var hour = this.padleft0(nowtime.getHours());
                var minute = this.padleft0(nowtime.getMinutes());
                var second = this.padleft0(nowtime.getSeconds());
                var millisecond = nowtime.getMilliseconds();
                millisecond = millisecond.toString().length == 1 ? "00" + millisecond : millisecond.toString().length == 2 ? "0" + millisecond : millisecond;
                return year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + second + "." + millisecond;
            },
            //补齐两位数  
            padleft0(obj) {
                return obj.toString().replace(/^[0-9]{1}$/, "0" + obj);
            }
        },
        mounted() {
            this.getFixTable()
        }
    }
</script>
<style>

</style>